<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
</head>
<body>
	<div id="msg" style="color: red;"></div>
	<form id="roleform" action="" data-th-object="${role}" method="post"
		accept-charset="utf-8">
		<input hidden="hidden" type="text" data-th-field="*{id}" name="id" id="id" />
		角色名称：<input type="text" data-th-field="*{rolename}" name="rolename" id="rolename"/>
		<br/><br/>
		是否隐藏敏感信息：<select data-th-field="*{secrecy}" id="secrecy" name="secrecy">
						<option value ="1">是</option>
					  	<option value ="0">否</option>
					</select>
		<h5>拥有菜单：</h5>
		<ul id="menutree" class="ztree"></ul>
	</form>
	<script>
		var setting = {
			check : {
				enable : true,
				chkboxType: { "Y" : "ps", "N" : "ps" }
			},
			data : {
				simpleData : {
					enable : true,
					pIdKey : "pid"
				}
			}
		};
		var zNodes;
		$.ajax({
			type : "POST",
			url : "/menu/getAllMenu",
			dataType : "json",
			async: false,
			success : function(data) {
				zNodes = data;
			}
		});
		$.fn.zTree.init($("#menutree"), setting, zNodes);
		var treeObj = $.fn.zTree.getZTreeObj("menutree");
		treeObj.expandAll(true);
		var cNodeIds;
		$.ajax({
			type : "GET",
			url : "/role/getOwnedMenuId",
			dataType : "json",
			data : $('#roleform').serialize(),
			async: false,
			success : function(data) {
				cNodeIds = data;
			}
		});
		if(cNodeIds){
			for(let i=0;i<cNodeIds.length;i++){
				var node = treeObj.getNodesByParam("id", ""+cNodeIds[i], null);
				if(node[0]){
					treeObj.checkNode(node[0], true, false);
				}
			}
		}
	</script>
</body>
</html>